#pragma once
#include "Vertex.h"
#define cVertex const Vertex

class Plane
{
private:
  mutable Vertex* _Vertex[3];
  _3D_Vector _Normal;                                                       // Ax + By + Cz = D
  uint _X, _Y;
  float _AdC, _BdC, _DdC;                                                   // A/C B/C D/C, C won't be zero
  
  void calc_normal ();
  void calc_coef ();
public:
  Plane () : _X (), _Y (), _AdC (), _BdC (), _DdC () {}
  Plane (uint x, uint y,
         Vertex* first, Vertex* second, Vertex* third);
  Plane (const Plane& right) { (*this) = right; }

  Plane& operator= (const Plane& right);

  void set_pos (uint x, uint y) { _X = x; _Y = y; }
  void set_vertex (Vertex* first, Vertex* second, Vertex* third);
  
  Vertex& operator[] (int i) const { return *(_Vertex[i]); }
  const Normal3f& normal () const { return _Normal; }
  const float altitude (float x, float y) const {
    return _DdC - _AdC * x - _BdC * y;
  }
};